package com.wc.alorithm_luogu.P4933_大师;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/3/15 14:19
 * @description https://www.luogu.com.cn/problem/P4933
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 1010, M = 40010;
    // f[i][j] 表示以i结尾,以j为公差的个数,加一是表示在j + i单独列
    // 转移f[i][a[i] - a[j]] += f[j][a[i] - a[j]] + 1;
    static int[][] f = new int[N][M];
    static int[] a = new int[N];
    static int P = 998244353;
    static int n;

    public static void main(String[] args) {
        n = sc.nextInt();
        for (int i = 1; i <= n; i++) a[i] = sc.nextInt();
        int res = 0;
        int p = 20000;
        for (int i = 1; i <= n; i++) {
            // 他自己本身也是可以的
            res++;
            for (int j = i - 1; j >= 1; j--) {
                int d = a[i] - a[j] + p;
                // 表示以i结尾的除了他自己，包括f[j][d]当中的个数，j + i单独来一下
                f[i][d] += f[j][d] + 1;
                f[i][d] %= P;
                // 以j结尾的，将i插入进去，多了f[j][d]因为前面都加过了, j + i单独来一下
                res += f[j][d] + 1;
                res %= P;
            }
        }
        out.println(res);
        out.flush();
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
